clear all
use "Data\W5 (Finaldata Post-Imputation).dta"

*****************8Table A9 The Results of The Sobel and Bootstrap Test***************8
sgmediation2 Democratic_Priority, mv(Understanding_of_Democracy) iv(Political_Values) cv(Country_Economic_Evaluation Family_Economic_Evaluation Social_Capital Political_Interest Political_Efficiency Election_Participation Internet_Use gender age education residence employment family_status household_income)

sgmediation2 Democratic_Necessity, mv(Understanding_of_Democracy) iv(Political_Values) cv(Country_Economic_Evaluation Family_Economic_Evaluation Social_Capital Political_Interest Political_Efficiency Election_Participation Internet_Use gender age education residence employment family_status household_income)

sgmediation2 Democratic_Priority, mv(Understanding_of_Democracy) iv(Social_Values) cv(Country_Economic_Evaluation Family_Economic_Evaluation Social_Capital Political_Interest Political_Efficiency Election_Participation Internet_Use gender age education residence employment family_status household_income)

sgmediation2 Democratic_Necessity, mv(Understanding_of_Democracy) iv(Social_Values) cv(Country_Economic_Evaluation Family_Economic_Evaluation Social_Capital Political_Interest Political_Efficiency Election_Participation Internet_Use gender age education residence employment family_status household_income)

bootstrap r(ind_eff) r(dir_eff), reps(1000): sgmediation2 Democratic_Priority, mv(Understanding_of_Democracy) iv(Political_Values) cv(Country_Economic_Evaluation Family_Economic_Evaluation Social_Capital Political_Interest Political_Efficiency Election_Participation Internet_Use gender age education residence employment family_status household_income)
estat bootstrap, percentile bc

bootstrap r(ind_eff) r(dir_eff), reps(1000): sgmediation2 Democratic_Necessity, mv(Understanding_of_Democracy) iv(Political_Values) cv(Country_Economic_Evaluation Family_Economic_Evaluation Social_Capital Political_Interest Political_Efficiency Election_Participation Internet_Use gender age education residence employment family_status household_income)
estat bootstrap, percentile bc

bootstrap r(ind_eff) r(dir_eff), reps(1000): sgmediation2 Democratic_Priority, mv(Understanding_of_Democracy) iv(Social_Values) cv(Country_Economic_Evaluation Family_Economic_Evaluation Social_Capital Political_Interest Political_Efficiency Election_Participation Internet_Use gender age education residence employment family_status household_income)
estat bootstrap, percentile bc

bootstrap r(ind_eff) r(dir_eff), reps(1000): sgmediation2 Democratic_Necessity, mv(Understanding_of_Democracy) iv(Social_Values) cv(Country_Economic_Evaluation Family_Economic_Evaluation Social_Capital Political_Interest Political_Efficiency Election_Participation Internet_Use gender age education residence employment family_status household_income)
estat bootstrap, percentile bc

****Since the bootstrap and sgmediation2 command cannot output the result we want directly, we manually construct file tableA9 by putdocx according to the output result in Results Window of stata.*****
putdocx begin  
putdocx paragraph, style(Heading1)  
putdocx paragraph, font("Times New Roman", 12, black)
putdocx text ("Table A9 The Results of The Sobel and Bootstrap Test")  
putdocx table mytable = (17, 6)  

putdocx table mytable(1, 1) = ("Treatment"), font("Times New Roman")  
putdocx table mytable(1, 2) = ("Outcome"), font("Times New Roman")  
putdocx table mytable(1, 3) = ("Effect"), font("Times New Roman")  
putdocx table mytable(1, 4) = ("Estimate"), font("Times New Roman")  
putdocx table mytable(1, 5) = ("Z-value"), font("Times New Roman")  
putdocx table mytable(1, 6) = ("95% Bias-corrected Confidence Interval"), font("Times New Roman")  

putdocx table mytable(2, 1) = ("Political Values (Sobel Test)"), font("Times New Roman")  
putdocx table mytable(2, 2) = ("Democratic Priority"), font("Times New Roman")  
putdocx table mytable(2, 3) = ("AME"), font("Times New Roman")  
putdocx table mytable(2, 4) = ("-0.006***"), font("Times New Roman")  
putdocx table mytable(2, 5) = ("-4.769"), font("Times New Roman")  
putdocx table mytable(2, 6) = (""), font("Times New Roman")  

putdocx table mytable(3, 1) = ("Political Values (Sobel Test)"), font("Times New Roman")  
putdocx table mytable(3, 2) = ("Democratic Priority"), font("Times New Roman")  
putdocx table mytable(3, 3) = ("ADE"), font("Times New Roman")  
putdocx table mytable(3, 4) = ("-0.107***"), font("Times New Roman")  
putdocx table mytable(3, 5) = ("-7.892"), font("Times New Roman")  
putdocx table mytable(3, 6) = (""), font("Times New Roman")  

putdocx table mytable(4, 1) = ("Political Values (Sobel Test)"), font("Times New Roman")  
putdocx table mytable(4, 2) = ("Democratic Necessity"), font("Times New Roman")  
putdocx table mytable(4, 3) = ("AME"), font("Times New Roman")  
putdocx table mytable(4, 4) = ("-0.005***"), font("Times New Roman")  
putdocx table mytable(4, 5) = ("-5.903"), font("Times New Roman")  
putdocx table mytable(4, 6) = (""), font("Times New Roman")  

putdocx table mytable(5, 1) = ("Political Values (Sobel Test)"), font("Times New Roman") 
putdocx table mytable(5, 2) = ("Democratic Necessity"), font("Times New Roman") 
putdocx table mytable(5, 2) = ("ADE"), font("Times New Roman")  
putdocx table mytable(5, 3) = ("-0.197***"), font("Times New Roman")  
putdocx table mytable(5, 4) = ("-24.311"), font("Times New Roman")  
putdocx table mytable(5, 6) = (""), font("Times New Roman")  

putdocx table mytable(6, 1) = ("Social Values (Sobel Test)"), font("Times New Roman")  
putdocx table mytable(6, 2) = ("Democratic Priority"), font("Times New Roman")  
putdocx table mytable(6, 3) = ("AME"), font("Times New Roman")  
putdocx table mytable(6, 4) = ("-0.006***"), font("Times New Roman")  
putdocx table mytable(6, 5) = ("-4.716"), font("Times New Roman")  
putdocx table mytable(6, 6) = (""), font("Times New Roman")  

putdocx table mytable(7, 1) = ("Social Values (Sobel Test)"), font("Times New Roman")  
putdocx table mytable(7, 2) = ("Democratic Priority"), font("Times New Roman")  
putdocx table mytable(7, 3) = ("ADE"), font("Times New Roman")  
putdocx table mytable(7, 4) = ("-0.120***"), font("Times New Roman")  
putdocx table mytable(7, 5) = ("-8.759"), font("Times New Roman")  
putdocx table mytable(7, 6) = (""), font("Times New Roman")  

putdocx table mytable(8, 1) = ("Social Values (Sobel Test)"), font("Times New Roman")  
putdocx table mytable(8, 2) = ("Democratic Necessity"), font("Times New Roman")  
putdocx table mytable(8, 3) = ("AME"), font("Times New Roman")  
putdocx table mytable(8, 4) = ("-0.005***"), font("Times New Roman")  
putdocx table mytable(8, 5) = ("-5.922"), font("Times New Roman")  
putdocx table mytable(8, 6) = (""), font("Times New Roman")  

putdocx table mytable(9, 1) = ("Social Values (Sobel Test)"), font("Times New Roman") 
putdocx table mytable(8, 2) = ("Democratic Necessity"), font("Times New Roman")  
putdocx table mytable(9, 3) = ("ADE"), font("Times New Roman")  
putdocx table mytable(9, 4) = ("-0.175***"), font("Times New Roman")  
putdocx table mytable(9, 5) = ("-21.247"), font("Times New Roman")  
putdocx table mytable(9, 6) = (""), font("Times New Roman")  

putdocx table mytable(10, 1) = ("Political Values (Bootstrap Test)"), font("Times New Roman")  
putdocx table mytable(10, 2) = ("Democratic Priority"), font("Times New Roman")  
putdocx table mytable(10, 3) = ("AME"), font("Times New Roman")  
putdocx table mytable(10, 4) = ("-0.006***"), font("Times New Roman")  
putdocx table mytable(10, 5) = ("-4.90"), font("Times New Roman")  
putdocx table mytable(10, 6) = ("Lower: -0.009, Upper: -0.004"), font("Times New Roman") 

putdocx table mytable(11, 1) = ("Political Values (Bootstrap Test)"), font("Times New Roman")
putdocx table mytable(11, 2) = ("Democratic Priority"), font("Times New Roman")     
putdocx table mytable(11, 3) = ("ADE"), font("Times New Roman")  
putdocx table mytable(11, 4) = ("-0.107***"), font("Times New Roman")  
putdocx table mytable(11, 5) = ("-7.52"), font("Times New Roman")  
putdocx table mytable(11, 6) = ("Lower: -0.137, Upper: -0.082"), font("Times New Roman") 

putdocx table mytable(12, 1) = ("Political Values (Bootstrap Test)"), font("Times New Roman") 
putdocx table mytable(12, 2) = ("Democratic Necessity"), font("Times New Roman") 
putdocx table mytable(12, 3) = ("AME"), font("Times New Roman")  
putdocx table mytable(12, 4) = ("-0.005***"), font("Times New Roman")  
putdocx table mytable(12, 5) = ("-5.93"), font("Times New Roman")  
putdocx table mytable(12, 6) = ("Lower: -0.007, Upper: -0.004"), font("Times New Roman") 

putdocx table mytable(13, 1) = ("Political Values (Bootstrap Test)"), font("Times New Roman")
putdocx table mytable(13, 2) = ("Democratic Necessity"), font("Times New Roman")   
putdocx table mytable(13, 3) = ("ADE"), font("Times New Roman")  
putdocx table mytable(13, 4) = ("-0.197***"), font("Times New Roman")  
putdocx table mytable(13, 5) = ("-20.83"), font("Times New Roman")  
putdocx table mytable(13, 6) = ("Lower: -0.216, Upper: -0.180"), font("Times New Roman")

putdocx table mytable(14, 1) = ("Social Values (Bootstrap Test)"), font("Times New Roman")  
putdocx table mytable(14, 2) = ("Democratic Priority"), font("Times New Roman")  
putdocx table mytable(14, 3) = ("AME"), font("Times New Roman")  
putdocx table mytable(14, 4) = ("-0.006***"), font("Times New Roman")  
putdocx table mytable(14, 5) = ("-4.69"), font("Times New Roman")  
putdocx table mytable(14, 6) = ("Lower: -0.009, Upper: -0.004"), font("Times New Roman")

putdocx table mytable(15, 1) = ("Social Values (Bootstrap Test)"), font("Times New Roman") 
putdocx table mytable(15, 2) = ("Democratic Priority"), font("Times New Roman")   
putdocx table mytable(15, 3) = ("ADE"), font("Times New Roman")  
putdocx table mytable(15, 4) = ("-0.120***"), font("Times New Roman")  
putdocx table mytable(15, 5) = ("-8.03"), font("Times New Roman")  
putdocx table mytable(15, 6) = ("Lower: -0.147, Upper: -0.089"), font("Times New Roman") 

putdocx table mytable(16, 1) = ("Social Values (Bootstrap Test)"), font("Times New Roman")
putdocx table mytable(16, 2) = ("Democratic Necessity"), font("Times New Roman")    
putdocx table mytable(16, 3) = ("AME"), font("Times New Roman")  
putdocx table mytable(16, 4) = ("-0.005***"), font("Times New Roman")  
putdocx table mytable(16, 5) = ("-6.07"), font("Times New Roman")  
putdocx table mytable(16, 6) = ("Lower: -0.007, Upper: -0.004"), font("Times New Roman")   

putdocx table mytable(17, 1) = ("Social Values (Bootstrap Test)"), font("Times New Roman")
putdocx table mytable(17, 2) = ("Democratic Necessity"), font("Times New Roman")      
putdocx table mytable(17, 3) = ("ADE"), font("Times New Roman")  
putdocx table mytable(17, 4) = ("-0.175***"), font("Times New Roman")  
putdocx table mytable(17, 5) = ("-17.49"), font("Times New Roman")  
putdocx table mytable(17, 6) = ("Lower: -0.194, Upper: -0.155"), font("Times New Roman")   

putdocx save "Results/Tables/Table A9 The Results of The Sobel and Bootstrap Test", replace